package com.baomibing.flow.service.impl;

import com.baomibing.core.common.SearchResult;
import com.baomibing.flow.dto.SysFlowInstanceDto;
import com.baomibing.flow.entity.SysFlowInstance;
import com.baomibing.flow.mapper.SysFlowInstanceMapper;
import com.baomibing.flow.service.SysFlowInstanceService;
import com.baomibing.orm.base.MBaseServiceImpl;
import com.baomibing.tool.util.Checker;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

/**
 * SysFlowInstanceServiceImpl
 *
 * @author frog 2023/10/16 10:23
 * @version 1.0.0
 **/
@Service
public class SysFlowInstanceServiceImpl extends MBaseServiceImpl<SysFlowInstanceMapper, SysFlowInstance, SysFlowInstanceDto> implements SysFlowInstanceService {

    @Override
    public void saveInstance(SysFlowInstanceDto instance) {
        saveIt(instance);
    }

    @Override
    public void updateInstance(SysFlowInstanceDto instance) {
        updateIt(instance);
    }

    @Override
    public SysFlowInstanceDto getInstance(String id) {
        return getIt(id);
    }

    @Override
    public SearchResult<SysFlowInstanceDto> searchByFlow(SysFlowInstanceDto v, int pageNumber, int pageSize) {
        if (Checker.beNull(v) || Checker.beEmpty(v.getFlowId())) {
            return new SearchResult<>(0, Lists.newArrayList());
        }
        LambdaQueryWrapper<SysFlowInstance> wrapper = lambdaQuery().eq(SysFlowInstance::getFlowId, v.getFlowId());
        return search(wrapper, pageNumber, pageSize);
    }
}
